package com.ziguang.redwood.admin.service;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.log.Log4jLog;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;


public class ProductTypeService {
	
	private static final Log4jLog log = Log4jLog.getLog(ProductTypeService.class);
	
	public static final ProductTypeService me = new ProductTypeService();
	
	/**
	 * 获取产品分类数据
	 */
	public List<Record> index(){
		List<Record> data=Db.find("select * from rw_product_type order by sort");
		return data;
	}
	
	/**
	 * 获取产品分类信息
	 */
	public Record QueryEdit(String id){
		Record data = Db.findFirst("select * from rw_product_type where id = ?",id);
		return data;
	}
	
	/**
	 * 增加/更新产品分类信息
	 */
	@Before(Tx.class)
	public void save(String id,String typeName,String sort,String typeImg){
		if(!id.isEmpty()){
			Db.update("update rw_product_type set type_name = ?,type_img = ?,sort = ? where id = ?",typeName,typeImg,sort,id);
		}else{
			Db.update("insert into rw_product_type (type_name,type_img,sort) values (?,?,?)",typeName,typeImg,sort);
		}
	}
	
	/**
	 * 删除当前数据
	 */
	public void delete(String id){
		Db.deleteById("rw_product_type", id);
	}
	
}
